<?php
// 应用公共文件

/**
 * 构建树形结构
 *
 * @param array $data
 * @param int   $parentId
 *
 * @return array
 */
function buildTree(array $data, int $parentId = 0):array
{
    $tree = [];
    foreach ($data as $item) {
        if ($item['parent_id'] === $parentId) {
            $children = buildTree($data, $item['value']);
            if (!empty($children)) {
                $item['children'] = $children;
            }
            $tree[] = $item;
        }
    }

    return $tree;
}


